<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>composition.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-painting-composition-example.html">Composition Modes</a></td><td >composition.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">composition.cpp 示例文件</h1>
<span class="subtitle">painting/composition/composition.cpp</span>
<!-- $$$painting/composition/composition.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the demonstration applications of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &quot;composition.h&quot;</span>
  <span class="preprocessor">#include &lt;QBoxLayout&gt;</span>
  <span class="preprocessor">#include &lt;QRadioButton&gt;</span>
  <span class="preprocessor">#include &lt;QTimer&gt;</span>
  <span class="preprocessor">#include &lt;QDateTime&gt;</span>
  <span class="preprocessor">#include &lt;QSlider&gt;</span>
  <span class="preprocessor">#include &lt;QMouseEvent&gt;</span>
  <span class="preprocessor">#include &lt;qmath.h&gt;</span>

  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
  <span class="preprocessor">#include &lt;QOpenGLFunctions&gt;</span>
  <span class="preprocessor">#include &lt;QOpenGLWindow&gt;</span>
  <span class="preprocessor">#endif</span>

  <span class="keyword">const</span> <span class="type">int</span> animationInterval <span class="operator">=</span> <span class="number">15</span>; <span class="comment">// update every 16 ms = ~60FPS</span>

  CompositionWidget<span class="operator">::</span>CompositionWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
      : <span class="type"><a href="qwidget.html">QWidget</a></span>(parent)
  {
      CompositionRenderer <span class="operator">*</span>view <span class="operator">=</span> <span class="keyword">new</span> CompositionRenderer(<span class="keyword">this</span>);

      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>mainGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(parent);
      mainGroup<span class="operator">-</span><span class="operator">&gt;</span>setTitle(tr(<span class="string">&quot;Composition Modes&quot;</span>));

      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>modesGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(mainGroup);
      modesGroup<span class="operator">-</span><span class="operator">&gt;</span>setTitle(tr(<span class="string">&quot;Mode&quot;</span>));

      rbClear <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Clear&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbClear<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setClearMode()));
      rbSource <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Source&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbSource<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setSourceMode()));
      rbDest <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Destination&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbDest<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setDestMode()));
      rbSourceOver <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Source Over&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbSourceOver<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setSourceOverMode()));
      rbDestOver <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Destination Over&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbDestOver<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setDestOverMode()));
      rbSourceIn <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Source In&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbSourceIn<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setSourceInMode()));
      rbDestIn <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Dest In&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbDestIn<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setDestInMode()));
      rbSourceOut <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Source Out&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbSourceOut<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setSourceOutMode()));
      rbDestOut <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Dest Out&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbDestOut<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setDestOutMode()));
      rbSourceAtop <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Source Atop&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbSourceAtop<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setSourceAtopMode()));
      rbDestAtop <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Dest Atop&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbDestAtop<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setDestAtopMode()));
      rbXor <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Xor&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbXor<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setXorMode()));

      rbPlus <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Plus&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbPlus<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setPlusMode()));
      rbMultiply <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Multiply&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbMultiply<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setMultiplyMode()));
      rbScreen <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Screen&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbScreen<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setScreenMode()));
      rbOverlay <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Overlay&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbOverlay<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setOverlayMode()));
      rbDarken <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Darken&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbDarken<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setDarkenMode()));
      rbLighten <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Lighten&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbLighten<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setLightenMode()));
      rbColorDodge <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Color Dodge&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbColorDodge<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setColorDodgeMode()));
      rbColorBurn <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Color Burn&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbColorBurn<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setColorBurnMode()));
      rbHardLight <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Hard Light&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbHardLight<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setHardLightMode()));
      rbSoftLight <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Soft Light&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbSoftLight<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setSoftLightMode()));
      rbDifference <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Difference&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbDifference<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setDifferenceMode()));
      rbExclusion <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qradiobutton.html">QRadioButton</a></span>(tr(<span class="string">&quot;Exclusion&quot;</span>)<span class="operator">,</span> modesGroup);
      connect(rbExclusion<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(setExclusionMode()));

      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>circleColorGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(mainGroup);
      circleColorGroup<span class="operator">-</span><span class="operator">&gt;</span>setTitle(tr(<span class="string">&quot;Circle color&quot;</span>));
      <span class="type"><a href="qslider.html">QSlider</a></span> <span class="operator">*</span>circleColorSlider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> circleColorGroup);
      circleColorSlider<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">0</span><span class="operator">,</span> <span class="number">359</span>);
      circleColorSlider<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Preferred<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed);
      connect(circleColorSlider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> view<span class="operator">,</span> SLOT(setCircleColor(<span class="type">int</span>)));

      <span class="type"><a href="qgroupbox.html">QGroupBox</a></span> <span class="operator">*</span>circleAlphaGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgroupbox.html">QGroupBox</a></span>(mainGroup);
      circleAlphaGroup<span class="operator">-</span><span class="operator">&gt;</span>setTitle(tr(<span class="string">&quot;Circle alpha&quot;</span>));
      <span class="type"><a href="qslider.html">QSlider</a></span> <span class="operator">*</span>circleAlphaSlider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> circleAlphaGroup);
      circleAlphaSlider<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">0</span><span class="operator">,</span> <span class="number">255</span>);
      circleAlphaSlider<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Preferred<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed);
      connect(circleAlphaSlider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> view<span class="operator">,</span> SLOT(setCircleAlpha(<span class="type">int</span>)));

      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>showSourceButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(mainGroup);
      showSourceButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Show Source&quot;</span>));
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>enableOpenGLButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(mainGroup);
      enableOpenGLButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Use OpenGL&quot;</span>));
      enableOpenGLButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
      enableOpenGLButton<span class="operator">-</span><span class="operator">&gt;</span>setChecked(view<span class="operator">-</span><span class="operator">&gt;</span>usesOpenGL());
  <span class="preprocessor">#endif</span>
      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>whatsThisButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(mainGroup);
      whatsThisButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;What's This?&quot;</span>));
      whatsThisButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);

      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>animateButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(mainGroup);
      animateButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Animated&quot;</span>));
      animateButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
      animateButton<span class="operator">-</span><span class="operator">&gt;</span>setChecked(<span class="keyword">true</span>);

      <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>viewLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>(<span class="keyword">this</span>);
      viewLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(view);
      viewLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(mainGroup);

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>mainGroupLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(mainGroup);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(circleColorGroup);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(circleAlphaGroup);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(modesGroup);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addStretch();
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(animateButton);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(whatsThisButton);
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(showSourceButton);
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      mainGroupLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(enableOpenGLButton);
  <span class="preprocessor">#endif</span>

      <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>modesLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>(modesGroup);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbClear<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbSource<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbDest<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbSourceOver<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbDestOver<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbSourceIn<span class="operator">,</span> <span class="number">5</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbDestIn<span class="operator">,</span> <span class="number">6</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbSourceOut<span class="operator">,</span> <span class="number">7</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbDestOut<span class="operator">,</span> <span class="number">8</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbSourceAtop<span class="operator">,</span> <span class="number">9</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbDestAtop<span class="operator">,</span> <span class="number">10</span><span class="operator">,</span> <span class="number">0</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbXor<span class="operator">,</span> <span class="number">11</span><span class="operator">,</span> <span class="number">0</span>);

      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbPlus<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbMultiply<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbScreen<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbOverlay<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbDarken<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbLighten<span class="operator">,</span> <span class="number">5</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbColorDodge<span class="operator">,</span> <span class="number">6</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbColorBurn<span class="operator">,</span> <span class="number">7</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbHardLight<span class="operator">,</span> <span class="number">8</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbSoftLight<span class="operator">,</span> <span class="number">9</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbDifference<span class="operator">,</span> <span class="number">10</span><span class="operator">,</span> <span class="number">1</span>);
      modesLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rbExclusion<span class="operator">,</span> <span class="number">11</span><span class="operator">,</span> <span class="number">1</span>);

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>circleColorLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(circleColorGroup);
      circleColorLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(circleColorSlider);

      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>circleAlphaLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>(circleAlphaGroup);
      circleAlphaLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(circleAlphaSlider);

      view<span class="operator">-</span><span class="operator">&gt;</span>loadDescription(<span class="string">&quot;:res/composition/composition.html&quot;</span>);
      view<span class="operator">-</span><span class="operator">&gt;</span>loadSourceFile(<span class="string">&quot;:res/composition/composition.cpp&quot;</span>);

      connect(whatsThisButton<span class="operator">,</span> SIGNAL(clicked(bool))<span class="operator">,</span> view<span class="operator">,</span> SLOT(setDescriptionEnabled(bool)));
      connect(view<span class="operator">,</span> SIGNAL(descriptionEnabledChanged(bool))<span class="operator">,</span> whatsThisButton<span class="operator">,</span> SLOT(setChecked(bool)));
      connect(showSourceButton<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> view<span class="operator">,</span> SLOT(showSource()));
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      connect(enableOpenGLButton<span class="operator">,</span> SIGNAL(clicked(bool))<span class="operator">,</span> view<span class="operator">,</span> SLOT(enableOpenGL(bool)));
  <span class="preprocessor">#endif</span>
      connect(animateButton<span class="operator">,</span> SIGNAL(toggled(bool))<span class="operator">,</span> view<span class="operator">,</span> SLOT(setAnimationEnabled(bool)));

      circleColorSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">270</span>);
      circleAlphaSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">200</span>);
      rbSourceOut<span class="operator">-</span><span class="operator">&gt;</span>animateClick();

      setWindowTitle(tr(<span class="string">&quot;Composition Modes&quot;</span>));
  }

  <span class="type">void</span> CompositionWidget<span class="operator">::</span>nextMode()
  {
      <span class="comment">/*
        if (!m_animation_enabled)
        return;
        if (rbClear-&gt;isChecked()) rbSource-&gt;animateClick();
        if (rbSource-&gt;isChecked()) rbDest-&gt;animateClick();
        if (rbDest-&gt;isChecked()) rbSourceOver-&gt;animateClick();
        if (rbSourceOver-&gt;isChecked()) rbDestOver-&gt;animateClick();
        if (rbDestOver-&gt;isChecked()) rbSourceIn-&gt;animateClick();
        if (rbSourceIn-&gt;isChecked()) rbDestIn-&gt;animateClick();
        if (rbDestIn-&gt;isChecked()) rbSourceOut-&gt;animateClick();
        if (rbSourceOut-&gt;isChecked()) rbDestOut-&gt;animateClick();
        if (rbDestOut-&gt;isChecked()) rbSourceAtop-&gt;animateClick();
        if (rbSourceAtop-&gt;isChecked()) rbDestAtop-&gt;animateClick();
        if (rbDestAtop-&gt;isChecked()) rbXor-&gt;animateClick();
        if (rbXor-&gt;isChecked()) rbClear-&gt;animateClick();
      */</span>
  }

  CompositionRenderer<span class="operator">::</span>CompositionRenderer(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
      : ArthurFrame(parent)
  {
      m_animation_enabled <span class="operator">=</span> <span class="keyword">true</span>;
      m_animationTimer <span class="operator">=</span> startTimer(animationInterval);
      m_image <span class="operator">=</span> <span class="type"><a href="../qtgui/qimage.html">QImage</a></span>(<span class="string">&quot;:res/composition/flower.jpg&quot;</span>);
      m_image<span class="operator">.</span>setAlphaChannel(<span class="type"><a href="../qtgui/qimage.html">QImage</a></span>(<span class="string">&quot;:res/composition/flower_alpha.jpg&quot;</span>));
      m_circle_alpha <span class="operator">=</span> <span class="number">127</span>;
      m_circle_hue <span class="operator">=</span> <span class="number">255</span>;
      m_current_object <span class="operator">=</span> NoObject;
      m_composition_mode <span class="operator">=</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_SourceOut;

      m_circle_pos <span class="operator">=</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">200</span><span class="operator">,</span> <span class="number">100</span>);

      setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Expanding<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Expanding);
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      m_pbuffer_size <span class="operator">=</span> <span class="number">1024</span>;
  <span class="preprocessor">#endif</span>
  }

  <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> rectangle_around(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> <span class="operator">&amp;</span>p<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="../qtcore/qsizef.html">QSizeF</a></span> <span class="operator">&amp;</span>size <span class="operator">=</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span>(<span class="number">250</span><span class="operator">,</span> <span class="number">200</span>))
  {
      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> rect(p<span class="operator">,</span> size);
      rect<span class="operator">.</span>translate(<span class="operator">-</span>size<span class="operator">.</span>width()<span class="operator">/</span><span class="number">2</span><span class="operator">,</span> <span class="operator">-</span>size<span class="operator">.</span>height()<span class="operator">/</span><span class="number">2</span>);
      <span class="keyword">return</span> rect;
  }

  <span class="type">void</span> CompositionRenderer<span class="operator">::</span>setAnimationEnabled(bool enabled)
  {
      <span class="keyword">if</span> (m_animation_enabled <span class="operator">=</span><span class="operator">=</span> enabled)
          <span class="keyword">return</span>;
      m_animation_enabled <span class="operator">=</span> enabled;
      <span class="keyword">if</span> (enabled) {
          Q_ASSERT(<span class="operator">!</span>m_animationTimer);
          m_animationTimer <span class="operator">=</span> startTimer(animationInterval);
      } <span class="keyword">else</span> {
          killTimer(m_animationTimer);
          m_animationTimer <span class="operator">=</span> <span class="number">0</span>;
      }
  }

  <span class="type">void</span> CompositionRenderer<span class="operator">::</span>updateCirclePos()
  {
      <span class="keyword">if</span> (m_current_object <span class="operator">!</span><span class="operator">=</span> NoObject)
          <span class="keyword">return</span>;
      <span class="type"><a href="../qtcore/qdatetime.html">QDateTime</a></span> dt <span class="operator">=</span> <span class="type"><a href="../qtcore/qdatetime.html">QDateTime</a></span><span class="operator">::</span>currentDateTime();
      <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> t <span class="operator">=</span> dt<span class="operator">.</span>toMSecsSinceEpoch() <span class="operator">/</span> <span class="number">1000.0</span>;

      <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> x <span class="operator">=</span> width() <span class="operator">/</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">2</span>) <span class="operator">+</span> (<a href="../qtcore/qtmath.html#qCos">qCos</a>(t<span class="operator">*</span><span class="number">8</span><span class="operator">/</span><span class="number">11</span>) <span class="operator">+</span> <a href="../qtcore/qtmath.html#qSin">qSin</a>(<span class="operator">-</span>t)) <span class="operator">*</span> width() <span class="operator">/</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">4</span>);
      <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> y <span class="operator">=</span> height() <span class="operator">/</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">2</span>) <span class="operator">+</span> (<a href="../qtcore/qtmath.html#qSin">qSin</a>(t<span class="operator">*</span><span class="number">6</span><span class="operator">/</span><span class="number">7</span>) <span class="operator">+</span> <a href="../qtcore/qtmath.html#qCos">qCos</a>(t <span class="operator">*</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">1.5</span>))) <span class="operator">*</span> height() <span class="operator">/</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">4</span>);

      setCirclePos(<span class="type"><a href="../qtcore/qlinef.html">QLineF</a></span>(m_circle_pos<span class="operator">,</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span>(x<span class="operator">,</span> y))<span class="operator">.</span>pointAt(<span class="number">0.02</span>));
  }

  <span class="type">void</span> CompositionRenderer<span class="operator">::</span>drawBase(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">&amp;</span>p)
  {
      p<span class="operator">.</span>setPen(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>NoPen);

      <span class="type"><a href="../qtgui/qlineargradient.html">QLinearGradient</a></span> rect_gradient(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> height());
      rect_gradient<span class="operator">.</span>setColorAt(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>red);
      rect_gradient<span class="operator">.</span>setColorAt(<span class="operator">.</span><span class="number">17</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>yellow);
      rect_gradient<span class="operator">.</span>setColorAt(<span class="operator">.</span><span class="number">33</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>green);
      rect_gradient<span class="operator">.</span>setColorAt(<span class="operator">.</span><span class="number">50</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>cyan);
      rect_gradient<span class="operator">.</span>setColorAt(<span class="operator">.</span><span class="number">66</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>blue);
      rect_gradient<span class="operator">.</span>setColorAt(<span class="operator">.</span><span class="number">81</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>magenta);
      rect_gradient<span class="operator">.</span>setColorAt(<span class="number">1</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>red);
      p<span class="operator">.</span>setBrush(rect_gradient);
      p<span class="operator">.</span>drawRect(width() <span class="operator">/</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> width() <span class="operator">/</span> <span class="number">2</span><span class="operator">,</span> height());

      <span class="type"><a href="../qtgui/qlineargradient.html">QLinearGradient</a></span> alpha_gradient(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> width()<span class="operator">,</span> <span class="number">0</span>);
      alpha_gradient<span class="operator">.</span>setColorAt(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>white);
      alpha_gradient<span class="operator">.</span>setColorAt(<span class="number">0.2</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>white);
      alpha_gradient<span class="operator">.</span>setColorAt(<span class="number">0.5</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>transparent);
      alpha_gradient<span class="operator">.</span>setColorAt(<span class="number">0.8</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>white);
      alpha_gradient<span class="operator">.</span>setColorAt(<span class="number">1</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>white);

      p<span class="operator">.</span>setCompositionMode(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_DestinationIn);
      p<span class="operator">.</span>setBrush(alpha_gradient);
      p<span class="operator">.</span>drawRect(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> width()<span class="operator">,</span> height());

      p<span class="operator">.</span>setCompositionMode(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_DestinationOver);

      p<span class="operator">.</span>setPen(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>NoPen);
      p<span class="operator">.</span>setRenderHint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>SmoothPixmapTransform);
      p<span class="operator">.</span>drawImage(rect()<span class="operator">,</span> m_image);
  }

  <span class="type">void</span> CompositionRenderer<span class="operator">::</span>drawSource(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">&amp;</span>p)
  {
      p<span class="operator">.</span>setPen(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>NoPen);
      p<span class="operator">.</span>setRenderHint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing);
      p<span class="operator">.</span>setCompositionMode(m_composition_mode);

      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> circle_rect <span class="operator">=</span> rectangle_around(m_circle_pos);
      <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> color <span class="operator">=</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span><span class="operator">::</span>fromHsvF(m_circle_hue <span class="operator">/</span> <span class="number">360.0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> m_circle_alpha <span class="operator">/</span> <span class="number">255.0</span>);
      <span class="type"><a href="../qtgui/qlineargradient.html">QLinearGradient</a></span> circle_gradient(circle_rect<span class="operator">.</span>topLeft()<span class="operator">,</span> circle_rect<span class="operator">.</span>bottomRight());
      circle_gradient<span class="operator">.</span>setColorAt(<span class="number">0</span><span class="operator">,</span> color<span class="operator">.</span>light());
      circle_gradient<span class="operator">.</span>setColorAt(<span class="number">0.5</span><span class="operator">,</span> color);
      circle_gradient<span class="operator">.</span>setColorAt(<span class="number">1</span><span class="operator">,</span> color<span class="operator">.</span>dark());
      p<span class="operator">.</span>setBrush(circle_gradient);

      p<span class="operator">.</span>drawEllipse(circle_rect);
  }

  <span class="type">void</span> CompositionRenderer<span class="operator">::</span>paint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>painter)
  {
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      <span class="keyword">if</span> (usesOpenGL() <span class="operator">&amp;</span><span class="operator">&amp;</span> glWindow()<span class="operator">-</span><span class="operator">&gt;</span>isValid()) {

          <span class="keyword">if</span> (<span class="operator">!</span>m_blitter<span class="operator">.</span>isCreated())
              m_blitter<span class="operator">.</span>create();

          <span class="type">int</span> new_pbuf_size <span class="operator">=</span> m_pbuffer_size;
          <span class="keyword">while</span> (size()<span class="operator">.</span>width() <span class="operator">&gt;</span> new_pbuf_size <span class="operator">|</span><span class="operator">|</span> size()<span class="operator">.</span>height() <span class="operator">&gt;</span> new_pbuf_size)
              new_pbuf_size <span class="operator">*</span><span class="operator">=</span> <span class="number">2</span>;

          <span class="keyword">while</span> (size()<span class="operator">.</span>width() <span class="operator">&lt;</span> new_pbuf_size<span class="operator">/</span><span class="number">2</span> <span class="operator">&amp;</span><span class="operator">&amp;</span> size()<span class="operator">.</span>height() <span class="operator">&lt;</span> new_pbuf_size<span class="operator">/</span><span class="number">2</span>)
              new_pbuf_size <span class="operator">/</span><span class="operator">=</span> <span class="number">2</span>;

          <span class="keyword">if</span> (<span class="operator">!</span>m_fbo <span class="operator">|</span><span class="operator">|</span> new_pbuf_size <span class="operator">!</span><span class="operator">=</span> m_pbuffer_size) {
              m_fbo<span class="operator">.</span>reset(<span class="keyword">new</span> <span class="type">QFboPaintDevice</span>(<span class="type"><a href="../qtcore/qsize.html">QSize</a></span>(new_pbuf_size<span class="operator">,</span> new_pbuf_size)<span class="operator">,</span> <span class="keyword">false</span><span class="operator">,</span> <span class="keyword">false</span>));
              m_pbuffer_size <span class="operator">=</span> new_pbuf_size;
          }

          <span class="keyword">if</span> (size() <span class="operator">!</span><span class="operator">=</span> m_previous_size) {
              m_previous_size <span class="operator">=</span> size();
              <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> p(m_fbo<span class="operator">.</span>data());
              p<span class="operator">.</span>setCompositionMode(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_Source);
              p<span class="operator">.</span>fillRect(<span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(<span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>)<span class="operator">,</span> size())<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>transparent);
              p<span class="operator">.</span>setCompositionMode(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>CompositionMode_SourceOver);
              drawBase(p);
              p<span class="operator">.</span>end();
              m_base_tex <span class="operator">=</span> m_fbo<span class="operator">-</span><span class="operator">&gt;</span>takeTexture();
          }

          painter<span class="operator">-</span><span class="operator">&gt;</span>beginNativePainting();
          {
              <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> p(m_fbo<span class="operator">.</span>data());
              p<span class="operator">.</span>beginNativePainting();
              m_blitter<span class="operator">.</span>bind();
              <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> targetRect(<span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>)<span class="operator">,</span> m_fbo<span class="operator">-</span><span class="operator">&gt;</span>size());
              <span class="keyword">const</span> QMatrix4x4 target <span class="operator">=</span> <span class="type"><a href="../qtgui/qopengltextureblitter.html">QOpenGLTextureBlitter</a></span><span class="operator">::</span>targetTransform(targetRect<span class="operator">,</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(<span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>)<span class="operator">,</span> m_fbo<span class="operator">-</span><span class="operator">&gt;</span>size()));
              m_blitter<span class="operator">.</span>blit(m_base_tex<span class="operator">,</span> target<span class="operator">,</span> <span class="type"><a href="../qtgui/qopengltextureblitter.html">QOpenGLTextureBlitter</a></span><span class="operator">::</span>OriginBottomLeft);
              m_blitter<span class="operator">.</span>release();
              p<span class="operator">.</span>endNativePainting();
              drawSource(p);
              p<span class="operator">.</span>end();
              m_compositing_tex <span class="operator">=</span> m_fbo<span class="operator">-</span><span class="operator">&gt;</span>takeTexture();
          }
          painter<span class="operator">-</span><span class="operator">&gt;</span>endNativePainting();

          painter<span class="operator">-</span><span class="operator">&gt;</span>beginNativePainting();
          <span class="keyword">auto</span> <span class="operator">*</span>funcs <span class="operator">=</span> <span class="type"><a href="../qtgui/qopenglcontext.html">QOpenGLContext</a></span><span class="operator">::</span>currentContext()<span class="operator">-</span><span class="operator">&gt;</span>functions();
          funcs<span class="operator">-</span><span class="operator">&gt;</span>glEnable(GL_BLEND);
          funcs<span class="operator">-</span><span class="operator">&gt;</span>glBlendEquation(GL_FUNC_ADD);
          funcs<span class="operator">-</span><span class="operator">&gt;</span>glBlendFunc(GL_ONE<span class="operator">,</span> GL_ONE_MINUS_SRC_ALPHA);
          m_blitter<span class="operator">.</span>bind();
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> targetRect(<span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>)<span class="operator">,</span> m_fbo<span class="operator">-</span><span class="operator">&gt;</span>size());
          <span class="keyword">const</span> QMatrix4x4 target <span class="operator">=</span> <span class="type"><a href="../qtgui/qopengltextureblitter.html">QOpenGLTextureBlitter</a></span><span class="operator">::</span>targetTransform(targetRect<span class="operator">,</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(<span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>)<span class="operator">,</span> size()));
          m_blitter<span class="operator">.</span>blit(m_compositing_tex<span class="operator">,</span> target<span class="operator">,</span> <span class="type"><a href="../qtgui/qopengltextureblitter.html">QOpenGLTextureBlitter</a></span><span class="operator">::</span>OriginBottomLeft);
          m_blitter<span class="operator">.</span>release();
          painter<span class="operator">-</span><span class="operator">&gt;</span>endNativePainting();
      } <span class="keyword">else</span>
  <span class="preprocessor">#endif</span>
      {
          <span class="comment">// using a QImage</span>
          <span class="keyword">if</span> (m_buffer<span class="operator">.</span>size() <span class="operator">!</span><span class="operator">=</span> size()) {
              m_buffer <span class="operator">=</span> <span class="type"><a href="../qtgui/qimage.html">QImage</a></span>(size()<span class="operator">,</span> <span class="type"><a href="../qtgui/qimage.html">QImage</a></span><span class="operator">::</span>Format_ARGB32_Premultiplied);
              m_base_buffer <span class="operator">=</span> <span class="type"><a href="../qtgui/qimage.html">QImage</a></span>(size()<span class="operator">,</span> <span class="type"><a href="../qtgui/qimage.html">QImage</a></span><span class="operator">::</span>Format_ARGB32_Premultiplied);

              m_base_buffer<span class="operator">.</span>fill(<span class="number">0</span>);

              <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> p(<span class="operator">&amp;</span>m_base_buffer);

              drawBase(p);
          }

          memcpy(m_buffer<span class="operator">.</span>bits()<span class="operator">,</span> m_base_buffer<span class="operator">.</span>bits()<span class="operator">,</span> m_buffer<span class="operator">.</span>sizeInBytes());

          {
              <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> p(<span class="operator">&amp;</span>m_buffer);
              drawSource(p);
          }

          painter<span class="operator">-</span><span class="operator">&gt;</span>drawImage(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> m_buffer);
      }
  }

  <span class="type">void</span> CompositionRenderer<span class="operator">::</span>mousePressEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>e)
  {
      setDescriptionEnabled(<span class="keyword">false</span>);

      <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> circle <span class="operator">=</span> rectangle_around(m_circle_pos);

      <span class="keyword">if</span> (circle<span class="operator">.</span>contains(e<span class="operator">-</span><span class="operator">&gt;</span>pos())) {
          m_current_object <span class="operator">=</span> Circle;
          m_offset <span class="operator">=</span> circle<span class="operator">.</span>center() <span class="operator">-</span> e<span class="operator">-</span><span class="operator">&gt;</span>pos();
      } <span class="keyword">else</span> {
          m_current_object <span class="operator">=</span> NoObject;
      }
      <span class="keyword">if</span> (m_animation_enabled) {
          killTimer(m_animationTimer);
          m_animationTimer <span class="operator">=</span> <span class="number">0</span>;
      }
  }

  <span class="type">void</span> CompositionRenderer<span class="operator">::</span>mouseMoveEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>e)
  {
      <span class="keyword">if</span> (m_current_object <span class="operator">=</span><span class="operator">=</span> Circle)
          setCirclePos(e<span class="operator">-</span><span class="operator">&gt;</span>pos() <span class="operator">+</span> m_offset);
  }

  <span class="type">void</span> CompositionRenderer<span class="operator">::</span>mouseReleaseEvent(<span class="type"><a href="../qtgui/qmouseevent.html">QMouseEvent</a></span> <span class="operator">*</span>)
  {
      m_current_object <span class="operator">=</span> NoObject;

      <span class="keyword">if</span> (m_animation_enabled) {
          Q_ASSERT(<span class="operator">!</span>m_animationTimer);
          m_animationTimer <span class="operator">=</span> startTimer(animationInterval);
      }
  }

  <span class="type">void</span> CompositionRenderer<span class="operator">::</span>timerEvent(<span class="type"><a href="../qtcore/qtimerevent.html">QTimerEvent</a></span> <span class="operator">*</span>event)
  {
      <span class="keyword">if</span> (event<span class="operator">-</span><span class="operator">&gt;</span>timerId() <span class="operator">=</span><span class="operator">=</span> m_animationTimer)
          updateCirclePos();
  }

  <span class="type">void</span> CompositionRenderer<span class="operator">::</span>setCirclePos(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qpointf.html">QPointF</a></span> <span class="operator">&amp;</span>pos)
  {
      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> oldRect <span class="operator">=</span> rectangle_around(m_circle_pos)<span class="operator">.</span>toAlignedRect();
      m_circle_pos <span class="operator">=</span> pos;
      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> newRect <span class="operator">=</span> rectangle_around(m_circle_pos)<span class="operator">.</span>toAlignedRect();
  <span class="preprocessor">#if QT_CONFIG(opengl)</span>
      <span class="keyword">if</span> (usesOpenGL()) {
          update();
          <span class="keyword">return</span>;
      }
  <span class="preprocessor">#endif</span>
      update(oldRect <span class="operator">|</span> newRect);
  }

</pre>
</div>
<!-- @@@painting/composition/composition.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
